package com.iseastar.guojiang.register;

import android.os.Bundle;
import android.view.View;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.map.TextureMapView;
import com.baidu.mapapi.model.LatLng;
import com.iseastar.BaseActivity2;
import com.iseastar.guojiang.dialog.DialogMgr;
import com.shouhuobao.station.R;

/**
 * 火箭侠注册业务培训地图导航
 * Created by lidandan on 2018/5/7.
 */

public class RegistegerBusinessTrainingMapActivity extends BaseActivity2 {
    private BaiduMap mBaiduMap;
    private TextureMapView mMapView = null;
    private double lat = 0;
    private double lon = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        lat = getIntent().getDoubleExtra("latitude", 0);
        lon = getIntent().getDoubleExtra("longitude", 0);
        super.onCreate(savedInstanceState);
        MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(new LatLng(lat, lon));
        mBaiduMap.animateMapStatus(u);
        addMarkmap();
    }

    @Override
    protected void findViewById() {
        setContentView(R.layout.register_business_training_map_activity);
        super.findViewById();
        getAppTitle().setCommonTitle("培训地点");
        mMapView = (TextureMapView) findViewById(R.id.training_mapView);
        findViewById(R.id.training_navigation_tv).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogMgr.showSelectMapToNavigation(getContext(), findViewById(R.id.training_navigation_tv), lat, lon, 0, 0);
            }
        });
        mBaiduMap = mMapView.getMap();
        //普通地图
        mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);
        mMapView.showZoomControls(false);//隐藏缩放按钮
        mMapView.showScaleControl(false);//隐藏比例尺
        mBaiduMap.setMyLocationEnabled(true);
    }

    public void addMarkmap() {
        mMapView.getMap().clear();
        LatLng llB = new LatLng(lat, lon);
        BitmapDescriptor bitmap = BitmapDescriptorFactory
                .fromResource(R.drawable.register_map_icon);
        OverlayOptions ooB = new MarkerOptions().position(llB).icon(bitmap).zIndex(9).draggable(true);
        mMapView.getMap().addOverlay(ooB);
    }

    @Override
    protected void onResume() {
        super.onResume();
        //在activity执行onResume时执行mMapView. onResume ()，实现地图生命周期管理
        mMapView.onResume();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mMapView.onSaveInstanceState(outState);

    }

    @Override
    public void onPause() {
        super.onPause();
        //在activity执行onPause时执行mMapView. onPause ()，实现地图生命周期管理
        mMapView.onPause();
    }

    @Override
    protected void onDestroy() {
        //在activity执行onDestroy时执行mMapView.onDestroy()，实现地图生命周期管理
        if (mBaiduMap != null) {
            mBaiduMap.clear();
        }
        mMapView.onDestroy();
        super.onDestroy();
    }
}

